home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DNet / DGoPlus.cpp < prev    next >
Encoding:
Text File  |  1996-07-05  |  7.8 KB  |  414 lines  |  [TEXT/R*ch]

  1. // DGopherPlus.cp
  2. // d.g.gilbert
  3.  
  4.  
  5.  
  6. #include <ncbi.h>
  7. #include <dgg.h>
  8. #include <Dvibrant.h>
  9.  
  10. #include "DTCP.h"
  11. #include "DGopher.h"
  12. #include "DGoList.h"
  13. #include "DGoInit.h"
  14. #include "DGoClasses.h"
  15.  
  16. #include "DGoPlus.h"
  17.  
  18.  
  19.  
  20.  
  21.  
  22. // DGoMenuBlock ------------------------------
  23.  
  24. #if 0
  25. class DGoMenuBlock : public DObject {
  26. public:
  27.     char*    fData;    // raw from server
  28.     DGopherList*    fGolist;
  29.     DGopher*     fParent;
  30.     
  31.     DGoMenuBlock(DGopher* itsParent, const char* itsData);
  32.     virtual ~DGoMenuBlock();
  33. };
  34. #endif
  35.  
  36. DGoMenuBlock::DGoMenuBlock(DGopher* itsParent, const char* itsData)
  37. {
  38.     fData= StrDup(itsData); //??
  39.     fParent= itsParent; //?? newOwner
  40.     fGolist= new DGopherList(fParent);
  41.     // fix fData so leading space is gone from it, 
  42.     // +MENU:cr
  43.     //  +INFO:...
  44.     //  +INFO:...
  45.     char *cp, *newp, thisc, lastc;
  46.     for (cp= newp= fData, lastc= 0; *cp; cp++) {
  47.         thisc= *cp;
  48.         if (!(thisc == ' ' && (lastc == kCR || lastc == kLF))) 
  49.             *newp++= thisc;
  50.         lastc= thisc;
  51.         }
  52.     *newp= 0;
  53.     fGolist->ReadLinks(fData);
  54. }
  55.  
  56. DGoMenuBlock::~DGoMenuBlock()
  57. {
  58.     MemFree(fData);
  59.     if (fGolist) { fGolist->FreeAllObjects(); fGolist->suicide(); }
  60. }
  61.  
  62.  
  63.  
  64.  
  65. #if 0
  66.  
  67. class DGoMenuItem : public DObject {
  68. public:
  69.     Boolean    fIsDefault;
  70.     DGoMenuItem() {}
  71. };
  72.  
  73. class DGoMenuRect : public DGoMenuItem {
  74. public:
  75.     Nlm_RecT    fRect;
  76.     DGoMenuRect(const char* itsData);
  77. };
  78.  
  79. class DGoMenuBytes : public DGoMenuItem {
  80. public:
  81.     long    fCharstart, fCharend;
  82.     DGoMenuBytes(const char* itsData);
  83. };
  84.  
  85. class DGoMenuLine : public DGoMenuItem {
  86. public:
  87.     long    fLinestart, fCharstart, fCharend;
  88.     DGoMenuLine(const char* itsData);
  89. };
  90.  
  91. class DGoMenuString : public DGoMenuItem {
  92. public:
  93.     char*    fFindstring;
  94.     short    fFindcount;
  95.     DGoMenuString(const char* itsData);
  96. };
  97.  
  98. #endif
  99.  
  100.  
  101.  
  102. // DGopherItemView ------------------------------
  103.  
  104.  
  105. DGopherItemView::DGopherItemView()
  106. {
  107.     Initialize("Text/plain");
  108. }
  109.  
  110.  
  111. DGopherItemView::DGopherItemView(const char* data) 
  112. {
  113.     Initialize( data);
  114. }
  115.  
  116. DObject* DGopherItemView::Clone()
  117. {
  118.     DGopherItemView* aClone = new DGopherItemView(this->fViewVal);
  119.     return aClone;
  120. }
  121.  
  122. DGopherItemView::~DGopherItemView()
  123. {
  124.     fViewVal= (char*) MemFree(fViewVal);
  125. }
  126.  
  127. //#define StrFromPointers(dst,src,sindex,slen,dmax)    Nlm_StrngSeg(dst,src,sindex,slen,dmax)
  128.  
  129. const char*    DGopherItemView::ViewVal()
  130. {
  131.     return  fViewVal;
  132. }
  133.  
  134. const char*    DGopherItemView::Kind() 
  135. {
  136.     static char gItembuf[256];
  137.     Nlm_StrngSeg( gItembuf, fViewVal, fIkind, fNkind, 256);
  138.     StrLocase(gItembuf); // added 1jan95
  139.     return gItembuf;
  140. }
  141.  
  142. const char* DGopherItemView::Handler()
  143. {
  144.     // this is obsolete -- we now keep this info w/ Kind()
  145.     static char gItembuf[256];
  146.     Nlm_StrngSeg( gItembuf, fViewVal, fIhandler, fNhandler, 256);
  147.     return gItembuf;
  148. }
  149.  
  150. const char*    DGopherItemView::ViewRequest() 
  151. {
  152.     //gItembuf = "\t+" + CStr255((unsigned char*)**fViewVal).Copy(fIkind, fNrequest);
  153.     // something is failing here b/n StrngSeg and return ?!
  154.     
  155.     static char gItembuf[256];
  156.     Nlm_StrngSeg( gItembuf+2, fViewVal, fIkind, fNrequest, 254);
  157.     gItembuf[0]= '\t';
  158.     gItembuf[1]= '+';
  159.     return gItembuf;
  160. }
  161.  
  162.  
  163. const char*    DGopherItemView::ViewStatus() 
  164. {
  165.     if (fViewStatus == kUnknownStatus) return "?";
  166.   else if (fViewStatus == kMaxStatus) return "*";
  167.   else return " "; 
  168. }
  169.  
  170.  
  171. const char*    DGopherItemView::Language()
  172. {
  173.     static char gItembuf[256];
  174.     Nlm_StrngSeg( gItembuf, fViewVal, fIlanguage, fNlanguage, 256);
  175.     return gItembuf;
  176. }
  177.  
  178. const char*    DGopherItemView::DataSize()
  179. {
  180.     static char gItembuf[256];
  181.     Nlm_StrngSeg( gItembuf, fViewVal, fIdatasize, fNdatasize, 256);
  182.     return gItembuf;
  183. }
  184.  
  185.  
  186. void DGopherItemView::Initialize(const char* line) 
  187. {
  188.     // "Text/Postscript German: <100k>"    
  189.     char *cp, *dp, *ep;
  190.     
  191.     fViewVal= NULL;
  192.     fViewStatus= kUnknownStatus;
  193.  
  194.     for (cp = (char*)line; *cp!=0 && *cp<=' '; cp++) ;
  195.     fViewVal= StrDup( cp);
  196.     StrLocase(fViewVal);
  197.     cp= fViewVal;
  198.     fIdatasize= 0;
  199.     fNdatasize= 0;
  200.  
  201.     dp= strchr( cp, ':');
  202.     if (dp) { 
  203.         char *sp = strchr( dp, '<');
  204.         if (sp) {
  205.             fIdatasize= long(sp+1 - cp);
  206.             ep= strchr( sp,'>'); 
  207.             if (ep) fNdatasize= long(ep - sp) - 1;
  208.             else fNdatasize= strlen(cp) - fIdatasize; 
  209.             }
  210.         }
  211.         
  212.     for (ep= cp; *ep!=0 && *ep>' ' && *ep!=':'; ep++) ;
  213.     Boolean dolang= (*ep != ':');
  214.     
  215.     // 14Mar94: drop separation of kind/handler 
  216.     // gopher+ & mime both use "/" as integral part of kind  
  217. #if 0
  218.     dp= strchr(cp, '/');
  219.     if (dp) {
  220.         fIkind= 0; // 1 + cp - cp
  221.         fNkind= long(dp - cp);
  222.         fIhandler= long(dp+1 - cp);
  223.         fNhandler= long(ep - dp) - 1;
  224.         fNrequest= long(ep - cp);
  225.         }
  226.     else
  227. #endif
  228.      {
  229.         fIkind= 0;
  230.         fNkind= long(ep - cp);
  231.         fIhandler= 0;
  232.         fNhandler= 0;
  233.         fNrequest= fNkind;
  234.         }
  235.     
  236.     if (dolang) {
  237.         for (dp = ep+1; *dp!=0 && *dp<=' '; dp++) ;
  238.         for (ep= dp; *ep!=0 && *ep>' ' && *ep!=':'; ep++) ;
  239.         fIlanguage= long(dp - cp);
  240.         fNlanguage= long(ep - dp) - 1;
  241.         fNrequest= long(ep - cp);
  242.         }
  243.     else {
  244.         fIlanguage= 0;
  245.         fNlanguage= 0;
  246.         }
  247. }
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256. // DGopherItemAsk ------------------------------
  257.  
  258.  
  259. DGopherItemAsk::DGopherItemAsk()
  260. {
  261.     Initialize(kGopherAskUnknown, "", "","");
  262. }
  263.  
  264. DGopherItemAsk::DGopherItemAsk(short kind, const char* question, 
  265.                                     const char* answer, const char* nametag, const char* valuetag)
  266. {
  267.     Initialize(kind, question, answer, nametag, valuetag);
  268. }
  269.  
  270. DGopherItemAsk::DGopherItemAsk(const char* data, Boolean isHTMLform)
  271. {
  272.     Initialize( data, isHTMLform);
  273. }
  274.  
  275. DGopherItemAsk::~DGopherItemAsk()
  276. {
  277.     MemFree( fQuestion);    
  278.     MemFree( fAnswer);    
  279.     MemFree( fNametag);
  280.     MemFree( fValuetag);
  281. }
  282.  
  283. DObject* DGopherItemAsk::Clone()
  284. {
  285.     DGopherItemAsk* aClone = new DGopherItemAsk(fKind, fQuestion, fAnswer, fNametag, fValuetag);
  286.     return aClone;
  287. }
  288.  
  289. void DGopherItemAsk::Initialize(const char* line, Boolean isHTMLform)
  290. {
  291.     //e.g., "Choose: Deliver electric shock to administrator now?|Yes|Not!"
  292.     char *cp, *ep, *myline, *quest = NULL, *ans = NULL, *name = NULL, *value= NULL;
  293.     short    kind = kGopherAskUnknown;
  294.     
  295.     for (cp = (char*)line; *cp!=0 && *cp<=' '; cp++) ;
  296.     cp= myline= StrDup( (char*)line);
  297.     
  298.     ep= StrChr( cp, ':');
  299.     if (ep) { 
  300.         *ep= 0;
  301.         if (0 == Strcasecmp( cp, "Ask") ) {
  302.             kind = kGopherAskAsk;
  303.             }
  304.         else if (0 == Strcasecmp( cp, "Choose") ) {
  305.             kind = kGopherAskChoose;
  306.             }
  307.         else if (0 == Strcasecmp( cp, "AskF") ) {
  308.             kind = kGopherAskAskF;
  309.             }
  310.         else if (0 == Strcasecmp( cp, "AskP") ) {
  311.             kind = kGopherAskAskP;
  312.             }
  313.         else if (0 == Strcasecmp( cp, "AskL") ) {
  314.             kind = kGopherAskAskL;
  315.             }
  316.         else if (0 == Strcasecmp( cp, "Select") ) {
  317.             kind = kGopherAskSelect;
  318.             }
  319.         else if (0 == Strcasecmp( cp, "ChooseF") ) {
  320.             kind = kGopherAskChooseF;
  321.             }
  322.         else if (0 == Strcasecmp( cp, "Note") ||
  323.                          0 == Strcasecmp( cp, "Comment") ) {
  324.             kind = kGopherAskNote;
  325.             }
  326.         cp= ep+1;
  327.         *ep= ':';
  328.  
  329.         if (isHTMLform) {
  330.             ep= StrChr( cp, ':');
  331.             if (ep) { 
  332.                 *ep= 0;
  333.                 name= StrDup(cp);
  334.                 cp= ep+1;
  335.                 *ep= ':';
  336.                 }
  337.             ep= StrChr( cp, ':');
  338.             if (ep) { 
  339.                 *ep= 0;
  340.                 value= StrDup(cp);
  341.                 cp= ep+1;
  342.                 *ep= ':';
  343.                 }
  344.             }
  345.  
  346.         }
  347.               
  348.     if (kind == kGopherAskUnknown) {
  349.         quest= StrDup("");
  350.         ans= StrDup("");
  351.         }
  352.     else if ((kind == kGopherAskSelect) && (NULL!=(ep= strchr( cp, ':'))) ) { 
  353.         *ep= 0;
  354.         quest= StrDup(cp);
  355.         cp= ep+1;
  356.         ans= StrDup(cp);
  357.         *ep= ':';
  358.         }
  359.     else if ((ep= strchr( cp, '\t'))!=NULL) { 
  360.         *ep= 0;
  361.         quest= StrDup(cp);
  362.         cp= ep+1;
  363.         ans= StrDup(cp);
  364.         *ep= '\t';
  365.         }
  366.     else {
  367.         quest= StrDup(cp);
  368.         ans= StrDup("");
  369.         }
  370.     MemFree(myline);
  371.  
  372. #if SILLYBOY
  373.     Initialize(kind,quest,ans,name);
  374.     MemFree(quest);
  375.     MemFree(ans);
  376.     MemFree(name);
  377. #else
  378.     fKind= kind;
  379.     fChoice= 1;
  380.     fQuestion    = quest;
  381.     fAnswer = ans;
  382.   fNametag= name;
  383.   fValuetag= value;
  384. #endif
  385. }
  386.  
  387. void DGopherItemAsk::Initialize(short kind, const char* question, 
  388.                                     const char* answer, const char* nametag, const char* valuetag)
  389. {
  390.     fKind= kind;
  391.     fChoice= 1;
  392.     fQuestion    = StrDup((char*) question);
  393.     fAnswer = StrDup((char*) answer);
  394.     fNametag    = StrDup((char*) nametag);
  395.     fValuetag    = StrDup((char*) valuetag);
  396. }
  397.  
  398.  
  399. void DGopherItemAsk::SetAnswer( const char* answer)
  400. {
  401.     MemFree( fAnswer);
  402.     fAnswer= StrDup((char*) answer);
  403. }
  404.  
  405.  
  406. void DGopherItemAsk::ItemChoice( short choice)
  407. {
  408.     fChoice= choice;
  409. }
  410.  
  411.  
  412.  
  413.  
  414.